import { uploadTransferNoApi } from "@/api/waybillManagement/customerServiceWaybill/index";
import { message } from "ant-design-vue";

export default function OperationHook(state: Base.GeneraDataType) {
  const { formStateTop, formStateBottom, emit, loading } = state;
  const submitHandle = () => {
    loading.value = true;
    const params = formStateTop.value.filter((t: any) => {
      return t.waybillNum && t.fastMail && t.transferNo;
    });

    if (!params.length) {
      loading.value = false;
      return message.error("请输入运单号、快递公司、转单号!");
    }

    uploadTransferNoApi(params)
      .then((res: any) => {
        const { code, data } = res;
        if (code === 200 && data.length === 0) {
          formStateTop.value = [];
          formStateBottom.value = [];
          message.success("操作成功!");
        } else {
          formStateBottom.value = data;
        }
      })
      .finally(() => (loading.value = false));
  };
  const cancelHandle = () => {
    emit("update:visible", false);
  };
  return {
    submitHandle,
    cancelHandle
  };
}
